/* 
 * @description: 地底部选择图片
 * @author: Jane 
 * @date: 2023-09-19 14:28:44
 */

import 'package:basic_common/common_exports.dart';

class BottomImagePickerTool {
  static void showBottomSheet(
      {required Function onCamera, required Function onGallery}) {
    //用于在底部打开弹框的效果
    showModalBottomSheet(
        builder: (BuildContext context) {
          //构建弹框中的内容
          return _buildBottomSheetWidget(context,
              onCamera: onCamera, onGallery: onGallery);
        },
        context: Get.context!);
  }

  static Widget _buildBottomSheetWidget(BuildContext context,
      {required Function onCamera, required Function onGallery}) {
    //弹框中内容  310 的调试
    return Container(
      height: ScreenHelper.height(160),
      child: Column(
        children: [
          _buildItem(title: "拍照", onTap: onCamera),
          //分割线
          Divider(),

          _buildItem(title: "选择相册", onTap: onGallery),

          Container(
            color: Colors.grey[300],
            height: 8,
          ),

          //取消按钮
          //添加个点击事件
          InkWell(
            onTap: () {
              Navigator.of(context).pop();
            },
            child: Container(
              child: Text("取消"),
              height: 44,
              alignment: Alignment.center,
            ),
          )
        ],
      ),
    );
  }

  static Widget _buildItem({required Function onTap, required String title}) {
    //添加点击事件
    return InkWell(
      //点击回调
      onTap: () {
        //关闭弹框
        Get.back();
        //外部回调
        if (onTap != null) {
          onTap();
        }
      },
      child: Container(
        height: 40,
        //左右排开的线性布局
        child: Row(
          //所有的子Widget 水平方向居中
          mainAxisAlignment: MainAxisAlignment.center,
          //所有的子Widget 竖直方向居中
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [Text(title)],
        ),
      ),
    );
  }
}
